import sys
from PyQt4.QtGui import QPushButton, QFont, QApplication, QWidget

class MixedButton(QPushButton):
	"""
	Print text over a four-image background

	Takes a string with the button text
	Keywords:
		parent: parent widget
		images: optional list of images (normal, hover, active, disabled)
	"""
	def __init__(self, text, parent=None, images=None, *args, **kw):
		QPushButton.__init__(self, parent, *args, **kw)
#
#		set the caption
#
		self.setText(text)

#
#		default size big enough for default images
#
		self.resize(210, 50)
#
#		should probably keyword the font name and size too
#
		self.setFont(QFont("Gabrielle", 24))

#
#		if no images supplied use the wmac standard blanks
#
		if images == None:
			images = [
				"resources/button_blank_normal.png",
				"resources/button_blank_hover.png",
				"resources/button_blank_active.png",
				"resources/button_blank_disabled.png",
			]
		self.set_images(*images)

#
#	set the images using a stylesheet
#
	def set_images(self, n, h, a, d):
		ss = MixedButton.ssfmt.format(n, h, a, d)
		self.setStyleSheet(ss)

#
#	stylesheet for QPushButton - all four states
#
	ssfmt = """
		QPushButton {{
			color		: yellow;
			background-image : url({0});
			border: 1px solid transparent;
			padding-top	: 8px;
		}}
		QPushButton:hover {{
			background-image : url({1});
		}}
		QPushButton:pressed {{
			background-image : url({2});
			padding-top	: 12px;
		}}
		QPushButton:disabled {{
			background-image : url({3});
		}}
	"""

if __name__ == "__main__":
	app = QApplication(sys.argv)
	top = QWidget()
	l = [
		"../../resources/button_blank_normal.png",
		"../../resources/button_blank_hover.png",
		"../../resources/button_blank_active.png",
		"../../resources/button_blank_disabled.png",
	]
	MixedButton("Foo", images=l, parent=top)

	top.show()
	sys.exit(app.exec_())

